<template>
    <div class="bac">
        <!-- <div>
            <img src="../assets/weiduoliya.png" alt="">
        </div> -->
        <van-form @submit="onSubmit" class="login-container" style="padding:6px">
            <h3 class="login_title">Secret Login</h3>
            <van-field v-model="username" name="username" label="帳号" placeholder="帳号"
                :rules="[{ required: true, message: '请填写帳号' }]" />
            <van-field v-model="password" type="password" name="password" label="密码" placeholder="密码"
                :rules="[{ required: true, message: '请填写密码' }]" />
            <div style="margin: 16px;">
                <van-button round block type="info" native-type="submit">登录</van-button>
            </div>
            <router-link style="color:#505458;font-size:18px" :to="{ path: '/zhuce' }">还没有账号?去注册</router-link>
        </van-form>

        <!-- <body id="poster">
            <el-form class="login-container" label-position="left" label-width="0px">
                <h3 class="login_title">Secret Login</h3>
                <el-form-item>
                    <el-input type="text" v-model="loginForm.username" name="username" auto-complete="off" placeholder="账号"></el-input>
                </el-form-item>

                <el-form-item>
                    <el-input type="password" v-model="loginForm.password" name="password" auto-complete="off" placeholder="密码">
                    </el-input>
                </el-form-item>

                <el-form-item style="width: 100%">
                    <el-button type="primary" style="width: 100%;background: #505458;border: none" v-on:click="login">登录
                    </el-button>
                </el-form-item>
                 <router-link :to="{ path: '/zhuce' }">还没有账号?去注册</router-link>
            </el-form>
           
        </body> -->
    </div>
</template>

<script>
import { fetchLogin } from '../api/user'
export default {
    data() {
        return {
            username: '',
            password: ''
        }
    },
    methods: {
        async onSubmit(fromData) {
            //请求登录接口
            let { message, status, token, userInfo } = await fetchLogin(fromData)
            this.$toast(message)
            if (status === 0) {
                // 把token登录态存到vuex并让vuex同步到locastrhost
                this.$store.commit('setToken', token)
                this.$store.commit('setUserInfo', userInfo)
                let { redirect } = this.$route.query;
                // 重定向参数 成功打回home首页界面
                if (redirect) {
                    this.$router.push(redirect)
                } else {
                    this.$router.push('/home')
                }
            } else {
                this.$store.commit('clearInfo')
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.bac {
    background: url("https://img0.baidu.com/it/u=1486219278,3321764833&fm=253&fmt=auto&app=138&f=JPEG?w=231&h=500") no-repeat;
    background-position: center;
    height: 100%;
    width: 100%;
    background-size: cover;
    position: fixed;
    background-color: transparent;
    .van-field{
        background: transparent;
    }
}

body {
    margin: 0px;
    padding: 0;
}

.login-container {
    border-radius: 15px;
    margin: 90px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    box-shadow: 0 0 25px #cac6c6;
    left: 0;
    bottom: 0;

}

.login_title {
    text-align: center;
    color: #505458;
}
</style>